package com.zut.hospital.service.pharmacy;

import com.alibaba.fastjson.JSON;
import com.zut.hospital.dao.pharmacy.InventoryMapper;
import com.zut.hospital.dao.pharmacy.MedicineMapper;
import com.zut.hospital.entity.pharmacy.Inventory;
import com.zut.hospital.entity.pharmacy.InventoryExample;
import com.zut.hospital.entity.pharmacy.Medicine;
import com.zut.hospital.entity.pharmacy.MedicineExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: hos-test
 * @description:
 * @author: 杨曼珍
 * @create: 2019-07-02 11:36
 **/
@Service
public class InventoryServiceImpl implements InventoryService {
    @Autowired
    InventoryMapper inventoryMapper;
    @Autowired
    MedicineMapper medicineMapper;

    public String layuiJsonParse(List<Map<String, String>> list, int size) {
        Map<String, Object> layuiMap = new HashMap<>();
        layuiMap.put("code", 1);
        layuiMap.put("msg", "success");
        layuiMap.put("count", size);
        layuiMap.put("data", list);
        return JSON.toJSONString(layuiMap);
    }
    //直线
    @Override
    public  String zhi() {
        MedicineExample medicineExample=new MedicineExample();
        List<Medicine> medicineList=medicineMapper.selectByExample(medicineExample);
        List<Map<String,String>>resaultmap=new ArrayList<>();
        Map<String,String>map;
        for (Medicine medicine:medicineList) {
            map=new HashMap<>();
            InventoryExample inventoryExample=new InventoryExample();
            inventoryExample.createCriteria().andIvtrMdcIdEqualTo(medicine.getId());
            Inventory inventory=inventoryMapper.selectByExample(inventoryExample).get(0);
            map.put("name",medicine.getMdcName());
            map.put("count",inventory.getIvtrCount().toString());
            resaultmap.add(map);
        }

        return layuiJsonParse(resaultmap,resaultmap.size());
    }

}
